// import * as Koa from 'koa';
import * as Router from 'koa-router';

import { template } from 'lodash';
import { Map } from 'immutable';

import { SocketServer } from '../../../socket/server';
import { RedisHelper } from '../../../redis/redis';

class Test {
    test: string;
    constructor(...message: string[]) {
        const c = template('<%= s1 %> !!!!! <%= s2 %>');
        let data = Map();
        for (let i = 0; i < message.length; i++) {
            data = data.set(`s${i + 1}`, message[i]);
        }
        this.test = c(data.toObject());
    }
}

// 这里是一个异步等待方法的示例
async function timeout(ms: number) {
    await new Promise((resolve) => {
        setTimeout(resolve, ms);
    });
}

async function wait(ms: number) {
    await timeout(ms);
}

export default async (ctx: Router.IRouterContext, next: () => Promise<any>): Promise<any> => {
    const t = new Test('周周来测试', '你没');
    const moment = require('moment');
    const x = new moment();
    const y = new moment();
    const d = moment.duration(y.diff(x)).as('seconds');

    const rtn = {
        name: 'get demo',
        message: '这是一个不带参数的 GET 请求',
        ip: ctx.request.ip,
        x, y, d
    };

    await wait(5000);

    ctx.body = rtn;
};
